package com.ruoyi.system.im.event;

import com.ruoyi.system.im.IMUserMessageTask;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@RequiredArgsConstructor
public class UserMessageHandler implements ApplicationListener<UserMessageEvent> {

    @Autowired
    private IMUserMessageTask imUserMessageTask;

    @Override
    @Async
    public void onApplicationEvent(UserMessageEvent event) {
        try {
            imUserMessageTask.userMessage();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
